package com.zjh.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> {

    private Integer code;
    private String msg;
    private T data;

    public Response(int code) {
        this.code = code;
    }

    public Response(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public Response(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Response(String msg, int code, T data) {
        this.code = code;
        this.msg = msg;
    }

    public static Response error(ResponseCode code, String msg) {
        return new Response(code.getCode(), msg, null);
    }

    public static <T> Response<T> success(T obj) {
        return new Response<>(ResponseCode.SUCCESS.getCode(), obj);
    }

    public static <T> Response<T> success(String msg, T obj) {
        return new Response<>(msg, ResponseCode.SUCCESS.getCode(), obj);
    }

    public static Response success() {
        return new Response<>(ResponseCode.SUCCESS.getCode());
    }

    public static Response error() {
        return new Response<>(ResponseCode.FAILED.getCode());
    }

    public static Response error(String msg) {
        return new Response(ResponseCode.FAILED.getCode(), msg);
    }

}
